﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana
{
    public sealed class AnimatorStateBehaviour : StateMachineBehaviour
    {
        [Tooltip("The state enter event to dispatch.")]
        [SerializeField]
        private AnimatorEvent[] enterActions;

        [SerializeField]
        [Tooltip("The state exit event to dispatch.")]
        private AnimatorEvent[] exitActions;

        public override void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            if (this.enterActions != null)
            {
                foreach (AnimatorEvent p in this.enterActions)
                {
                    p.Excute(animator, stateInfo);
                }
            }
        }

        public override void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            if (this.exitActions != null)
            {
                foreach (AnimatorEvent p in this.exitActions)
                {
                    p.Excute(animator, stateInfo);
                }
            }
        }
    }
}

